import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'

import Vant from 'vant';
import 'vant/lib/index.css';

import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
// 引入
import axios from './util/request.js'
Vue.prototype.$http = axios
import '@/assets/css/reset.css'
import {
  Toast
} from 'vant'

var aaa
axios.interceptors.request.use((conf) => {
  aaa = Toast.loading({
    message: '加载中.',
    forbidClick: true,
  });
  return conf
})
axios.interceptors.response.use((conf) => {
  aaa.clear()
  return conf
})

var instance = axios.create({
  timeout: 6000
})

// 定义一个全局变量,然后接着toast的变量
var toast;

// 配置拦截器
instance.interceptors.request.use(
  (config) => {
    toast = Toast.loading({
      message: '加载中',
      forbidClick: true
    })
    return config
  },
  (err) => {
    new Error('请求有问题')
  }
)
// 响应拦截器
instance.interceptors.response.use(
  (res) => {
    toast.clear()
    return res
  }
)

Vue.use(ElementUI)

Vue.use(Vant);

// 文本格式化处理     全局过滤器
// Vue.filter('fromdate', (v) => {
//   var d = new Date(v)
//   var y = d.getFullYear()
//   var m = (d.getMonth() + 1 + '').padStart(2, '0')
//   var dd = (d.getDate() + '').padStart(2, '0')

//   var h = (d.getHours() + '').padStart(2, '0')
//   var mm = (d.getMinutes() + '').padStart(2, '0')
//   var ss = (d.getSeconds() + '').padStart(2, '0')

//   return `${y}年${m}月${dd}日 ${h}:${mm}:${ss}`

// })

Vue.config.productionTip = false

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')